package com.effectivcrm.controller



import com.effectivcrm.domain.Lead;
import com.effectivcrm.service.LeadService

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/lead")
class LeadRestController {

	@Autowired
	LeadService service;
	
	
	@RequestMapping( method=RequestMethod.POST )
	Lead create( @RequestBody  Lead lead ){
		
		System.out.println("Received lead to save - " + lead);
		
		return service.create(lead);
	}
	
	@RequestMapping(value="/{id}" , method=RequestMethod.GET )
	Lead findOne( @PathVariable String id){
		return service.findOne(lead);
	}
	
	@RequestMapping( method=RequestMethod.PUT )
	int update(@RequestBody  Lead lead) {
		return service.update(lead);
	}
	
	@RequestMapping(value="/{id}", method=RequestMethod.DELETE )
	int delete(@PathVariable String id){
		return service.delete(id);
	}
	
	@RequestMapping(value = "/list/{viewName}", method=RequestMethod.GET )
	List<Lead> list( @PathVariable String viewName){
		return service.findAll(viewName);
	}
	
}
